﻿
function main() {
    var testVersion = "(201901021555)版";
    var softwareName = "抖音";
    var view = RequestEngine.getWebView();
    var viewJson = JSON.parse(view);
    var search = viewJson.search;
    var zfNum = viewJson.zfNum;
    var yazfs = viewJson.yazfs;
	var contentArr = viewJson.contentArr;

    AccessibilityEngine.sleepEngine(5000);//等待
	if (AccessibilityEngine.checkUpId(widget.pages.shouye.wzdl) == ISTRUE) { //我知道了
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.wzdl);
		}
    // chuSiHua(widget.pages.shouye.bugengxin);
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
    }
	
	if (AccessibilityEngine.checkUpId(widget.pages.shouye.wzdl) == ISTRUE) { //我知道了
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.wzdl);
		}
    var jixing = getXYByIdIndex(widget.pages.shouye.wode);
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
    }
    AccessibilityEngine.mockOnClickId(widget.pages.shouye.shousuo); // 点击搜索 放大镜
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
    }
	//点击赋值框
     if( jixing == 1 ){
        ScreenEngine.swipe(parseX(300), parseY(100), parseX(300), parseY(100), 500); //点击
    } else if( jixing == 2 ){
        ScreenEngine.swipe(parseX(400), parseY(100), parseX(400), parseY(100), 500); //点击
    }
	
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
    }
    AccessibilityEngine.sleepEngine(2000);//等待
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) {//更新以后再说
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
    }
    AccessibilityEngine.mockEditId(widget.pages.shouye.shousuopinglunKuang,search); //赋值搜索框
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) {//更新以后再说
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
    }
    AccessibilityEngine.sleepEngine(2000);//等待

    //搜索按钮
    if (jixing == 1) {
        ScreenEngine.swipe(parseX(665), parseY(1219), parseX(665), parseY(1219), 500); //点击
    } else if (jixing == 2) {
		AccessibilityEngine.sleepEngine(5000);//等待
		//ScreenEngine.swipe(parseX(480), parseY(715), parseX(480), parseY(715), 500); //点击
		ScreenEngine.swipe(parseX(700), parseY(1200), parseX(700), parseY(1200), 500); //点击		
    }
	
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
    }
    AccessibilityEngine.sleepEngine(3000);//等待
    if ( AccessibilityEngine.checkUpId(widget.pages.shousuoyemian.shousuomingzi) == ISTRUE ){
        AccessibilityEngine.mockOnClickIdIndex(widget.pages.shousuoyemian.shousuomingzi,0); // 点击第一个名字
    }else {
        showLog("搜索抖音号不存在");
        setTaskState("5", "搜索抖音号不存在");
        throw SyntaxError();
    }
    AccessibilityEngine.sleepEngine(2000);//等待
    if ( AccessibilityEngine.checkUpId(widget.pages.shousuoyemian.shipinkuang) == ISTRUE){
        //AccessibilityEngine.mockOnClickIdIndex(widget.pages.shousuoyemian.shipinkuang,0); // 点击第一个视频
		
		AccessibilityEngine.mockOnClickClassDesc("android.widget.ImageView","视频"+zfNum);
		AccessibilityEngine.sleepEngine(2000);//等待
		
		//转发 Begin
		if( jixing == 1 ){
			// showLog("11111111")
			// var pressjixing = "press," + parseX(660) + "," + parseY(905);
			// ScreenEngine.currency(pressjixing);
			// AccessibilityEngine.sleepEngine(2000);//等待
			// showLog("22222222")
			ScreenEngine.swipe(parseX(660), parseY(905), parseX(660), parseY(905), 500); //从下往上滑动
		} else if( jixing == 2 ){
			ScreenEngine.swipe(parseX(667), parseY(910), parseX(667), parseY(910), 500); //从下往上滑动
		}
		AccessibilityEngine.sleepEngine(2000);//等待
		AccessibilityEngine.mockOnClickIdText("com.ss.android.ugc.aweme:id/d46","转发"); // 点击转发
		AccessibilityEngine.sleepEngine(2000);//等待
		var search2 = contentArr[Math.floor(Math.random()*contentArr.length)];
		showLog(search2+"search2");
		AccessibilityEngine.mockEditId(widget.pages.shouye.pinglunKuang, search2); //赋值
		AccessibilityEngine.sleepEngine(2000);//等待
		AccessibilityEngine.mockOnClickId(widget.pages.shouye.fasong); // 发送
		ScreenEngine.swipe(parseX(450), parseY(900), parseX(450), parseY(200), 500);
		//转发 End
		
    }else {
        showLog("搜索抖音号不存在");
        setTaskState("5", "搜索抖音号不存在");
        throw SyntaxError();
    }
    AccessibilityEngine.sleepEngine(10000);//等待
    setTaskState("5", "执行成功");
    throw SyntaxError();
}


var publicfunction = RequestEngine.getPluginPath() + "OS_DYCOMMON/publicfunction.js";
include(publicfunction); //公共方法js
var widgetPath = dyConditionCheck();
var widgetbyid = RequestEngine.getPluginPath() +"OS_DYCOMMON/"+ widgetPath;
include(widgetbyid);
main();